<?php

namespace Gql\Response;


use Gql\Errors\SafeException;

trait  ResponseTrait
{

    public static function send($data = null, $message = null)
    {
        if ($data instanceof \Exception) {
            return new SafeException($data->getMessage() . $data->getFile() . $data->getLine());
        }elseif ($data instanceof SafeException){
            return $data;
        }

        if (!is_null($message) && is_array($data) || $data instanceof \ArrayAccess) {
            if (!isset($data['_message'])) $data['_message'] = $message;
        }
        return $data;

    }

}